package cn.edu.nju.software.cdiy.action.user.all;

import java.util.List;
import java.util.Map;

import cn.edu.nju.software.cdiy.bean.Scheme;
import cn.edu.nju.software.cdiy.bean.Scomment;
import cn.edu.nju.software.cdiy.service.SchemeService;
import cn.edu.nju.software.cdiy.service.ScommentService;
import cn.edu.nju.software.cdiy.util.BusinessConstant;
import cn.edu.nju.software.cdiy.util.Constant;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class SchemeDetailAction extends ActionSupport {

	private SchemeService schemeService;
	private ScommentService scommentService;
	private long id;
	private Scheme scheme;
	private Map<String,List<Scheme>> relatedSchemes;
	private List<Scomment> scommentList;
	private int totalPage;
	private int page;
	private int totalLength;
	
	public void setSchemeService(SchemeService schemeService) {
		this.schemeService = schemeService;
	}

	public void setScommentService(ScommentService scommentService) {
		this.scommentService = scommentService;
	}

	public void setId(long id) {
		this.id = id;
	}

	public Scheme getScheme() {
		return scheme;
	}

	public Map<String, List<Scheme>> getRelatedSchemes() {
		return relatedSchemes;
	}

	public List<Scomment> getScommentList() {
		return scommentList;
	}

	public void setScommentList(List<Scomment> scommentList) {
		this.scommentList = scommentList;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getTotalLength() {
		return totalLength;
	}

	public void setTotalLength(int totalLength) {
		this.totalLength = totalLength;
	}

	@Override
	public String execute() throws Exception {
		scheme = schemeService.getSchemeById(id);
		relatedSchemes = schemeService.getRelatedSchemes(scheme);

		totalLength = scommentService.getScommentSize(id);
		totalPage = totalLength / Constant.PAGE_LENGTH + 1;
		if (page == 0) {
			page = 1;
		}
		scommentList = scommentService.getScommentSelectList(id, page, Constant.PAGE_LENGTH);

		return SUCCESS;
	}

	public String getSelectPage() {
		scommentList = scommentService.getScommentSelectList(id, page, Constant.PAGE_LENGTH);
		return SUCCESS;
	}

}
